package com.yinp.proapp.module.wanandroid;

import android.content.Context;

import com.yinp.proapp.manger.BaseManager;
import com.yinp.proapp.module.wanandroid.bean.AddCollectBean;
import com.yinp.proapp.module.wanandroid.bean.CollectionListBean;
import com.yinp.proapp.module.wanandroid.bean.NavigationListBean;
import com.yinp.proapp.module.wanandroid.bean.RankListBean;
import com.yinp.proapp.module.wanandroid.bean.WanOfficialAccountBean;
import com.yinp.proapp.module.wanandroid.bean.WanOfficialAccountListBean;
import com.yinp.proapp.module.wanandroid.bean.WanProjectListBean;
import com.yinp.proapp.module.wanandroid.bean.WanQuestionAnswerBean;
import com.yinp.proapp.module.wanandroid.bean.WanSquareListBean;
import com.yinp.proapp.module.wanandroid.bean.WanSysListBean;
import com.yinp.proapp.module.wanandroid.interfaces.CollectListener;
import com.yinp.proapp.module.wanandroid.web.retrofit.WanBuildRetrofit;
import com.yinp.proapp.module.wanandroid.web.retrofit.WanData;
import com.yinp.proapp.module.wanandroid.web.retrofit.WanData2;
import com.yinp.proapp.module.wanandroid.web.retrofit.WanObserver;
import com.yinp.proapp.module.wanandroid.web.retrofit.WanObserver2;

import java.util.List;

/**
 * wanData和wanData2两种不同和的数据解析方式
 */
public class WanManager extends BaseManager {

    public WanManager(Context context) {
        super(context);
    }

    /**
     * 获取顶部banner
     *
     * @param baseObserver
     */
    public void getBannerList(WanObserver<WanData> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().getBannerList(), baseObserver);
    }

    /**
     * 获取首页文章列表
     *
     * @param size
     * @param baseObserver
     */
    public void getHomeList(int size, WanObserver<WanData> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().getHomArticleList(size), baseObserver);
    }

    /**
     * 获取置顶文章
     *
     * @param baseObserver
     */
    public void getStickList(WanObserver<WanData> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().getStickList(), baseObserver);
    }

    /**
     * 登录
     *
     * @param baseObserver
     */
    public void login(String username, String password, WanObserver<WanData> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().login(username, password), baseObserver);
    }

    /**
     * 获取自己积分数量
     *
     * @param baseObserver
     */
    public void getIntegral(WanObserver<WanData> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().getIntegral(), baseObserver);
    }

    /**
     * 获取积分排行榜
     *
     * @param baseObserver
     */
    public void getRankList(int page, WanObserver2<WanData2<RankListBean>> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().getRankList(page), baseObserver);
    }

    /**
     * 获取自体系列表
     *
     * @param baseObserver
     */
    public void getSystemInfo(WanObserver2<WanData2<List<WanSysListBean>>> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().getSystemList(), baseObserver);
    }

    /**
     * 获取收藏文章列表
     *
     * @param page
     * @param baseObserver
     */
    public void getCollectedList(int page, WanObserver2<WanData2<CollectionListBean>> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().getCollectList(page), baseObserver);
    }

    /**
     * 退出的登录
     *
     * @param baseObserver
     */
    public void loginOut(WanObserver2<WanData2<String>> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().loginOut(), baseObserver);
    }

    /**
     * 获取收藏文章列表
     *
     * @param baseObserver
     */
    public void getNavigationList(WanObserver2<WanData2<List<NavigationListBean>>> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().getNavigationList(), baseObserver);
    }

    /**
     * 获取广场列表数据
     *
     * @param baseObserver
     */
    public void getSquareList(int page, WanObserver2<WanData2<WanSquareListBean>> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().getSquareList(page), baseObserver);
    }

    /**
     * 获取项目列表数据
     *
     * @param baseObserver
     */
    public void getProjectList(int page, WanObserver2<WanData2<WanProjectListBean>> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().getProjectList(page), baseObserver);
    }

    /**
     * 添加收藏
     */
    public void addCollect(int id, CollectListener listener) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().addCollect(id), new WanObserver2<WanData2<AddCollectBean>>() {
            @Override
            public void onSuccess(WanData2<AddCollectBean> o) {
                if (o != null) {
                    if (o.getErrorCode() == 0) {
                        showToast("收藏类容");
                        listener.Success();
                    } else {
                        showToast("收藏失败");
                        listener.Failed();
                    }
                }
            }

            @Override
            public void onCodeFail(String msg, int code) {
                showToast("收藏失败");
                listener.Failed();
            }
        });
    }

    /**
     * 取消收藏
     */
    public void cancelCollect(int id, CollectListener listener) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().cancelCollect(id), new WanObserver2<WanData2<AddCollectBean>>() {
            @Override
            public void onSuccess(WanData2<AddCollectBean> o) {
                if (o != null) {
                    if (o.getErrorCode() == 0) {
                        showToast("取消收藏");
                        listener.Success();
                    } else {
                        showToast("取消失败");
                        listener.Failed();
                    }
                }
            }

            @Override
            public void onCodeFail(String msg, int code) {
                showToast("取消失败");
                listener.Failed();
            }
        });
    }

    /**
     * 获取问答列表
     *
     * @param baseObserver
     */
    public void getQuestionAnswerList(int page, WanObserver2<WanData2<WanQuestionAnswerBean>> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().getQuestionAnswerList(page), baseObserver);
    }

    /**
     * 获取公众号列表
     *
     * @param baseObserver
     */
    public void getOfficialAccount(WanObserver2<WanData2<List<WanOfficialAccountBean>>> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().getOfficialAccount(), baseObserver);
    }

    /**
     * 通过id获取公众号列表
     *
     * @param baseObserver
     */
    public void getOfficialAccountList(int id, int page, WanObserver2<WanData2<WanOfficialAccountListBean>> baseObserver) {
        addDisposable(WanBuildRetrofit.getInstance().getWanApiRetrofit().getOfficialAccountList(id, page), baseObserver);
    }
}
